//
//  EvaluateCell.m
//  wtshoppingcite
//
//  Created by TW on 14-11-21.
//  Copyright (c) 2014年 TW. All rights reserved.
//

#import "EvaluateCell.h"
#import "UIUtility.h"

@implementation EvaluateCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}

-(void)createSubViews{
    
    _iconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 40, 40)];
    _iconImageView.layer.cornerRadius = 20;
    _iconImageView.image = [UIImage imageNamed:@""];
    _iconImageView.clipsToBounds = YES;
    [self.contentView addSubview:_iconImageView];
    
    _nickNameLable = [self createLabelWithFrame:CGRectMake(_iconImageView.right +10, 5, 80, 30) text:@"" font:18 textAli:NSTextAlignmentLeft textColor:MAIN_BLACK_COLOR];
    [self addSubview:_nickNameLable];
    
    _levelImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 25, 25)];
    [self.contentView addSubview:_levelImageView];
  
    
    _dateLable = [self createLabelWithFrame:CGRectMake(_nickNameLable.left, _nickNameLable.bottom, 120, 18) text:@"" font:12 textAli:NSTextAlignmentLeft textColor:UIColorFromRGB(0x9fa0a0)];
    [self addSubview:_dateLable];
    
    
    _textLable = [self createLabelWithFrame:CGRectMake(_dateLable.left, _dateLable.bottom, 230, 40) text:@"" font:13 textAli:NSTextAlignmentLeft textColor:UIColorFromRGB(0x9fa0a0)];
    _textLable.numberOfLines = 0;
    [self addSubview:_textLable];
    
}

-(void)setEvaluateModel:(EvaluateModel *)evaluateModel{
    if (_evaluateModel != evaluateModel) {
        _evaluateModel =evaluateModel;
        
       // _iconImageView.image =[UIImage imageNamed: _evaluateModel.avatar];
        [_iconImageView setImageWithURL:[NSURL URLWithString: _evaluateModel.avatar] placeholderImage:[UIImage imageNamed:@"touxiang_org"]];
        
        if ([_nickNameLable.text isEqual:@""] || _nickNameLable.text == nil) {
            _nickNameLable.text = @"未知名";
        }else{
            _nickNameLable.text = _evaluateModel.nickName;
        }
        _dateLable.text = _evaluateModel.time;
        _textLable.text = _evaluateModel.comment;
        
         CGFloat weith = [UIUtility getLabelWidthOfText:_nickNameLable.text andFont:[UIFont systemFontOfSize:18]];
        _levelImageView.left =_iconImageView.right + weith + 10;
        _levelImageView.image = [UIImage imageNamed:_evaluateModel.level];
    }
}

-(UILabel*)createLabelWithFrame:(CGRect)frame text:(NSString*)text font:(int)font textAli:(NSTextAlignment)alig textColor:(UIColor*)tc{
    if(text == nil)
        text = @"";
    UILabel* label = [[UILabel alloc] initWithFrame:frame];
    label.text = text;
    label.font = [UIFont systemFontOfSize:font];
    label.textAlignment = alig;
    label.textColor = tc;
    label.numberOfLines = 0;
    label.backgroundColor = [UIColor clearColor];
    return label;
}
@end
